package com.yun.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yun.Vo.ResultMessasge;
import com.yun.client.Httpclient;
import com.yun.pojo.PhoneInfo;
import com.yun.service.impl.AddPhoneServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequestMapping("/GetInfo")
public class GetPhoneInfoController {
    @Autowired
    private Httpclient httpclient;
    @Autowired
    private AddPhoneServiceImpl addPhoneService;
    private String url = "https://cn.apihz.cn/api/ip/shouji.php?id=10001988&key=433d4fe8b49a034f34990cb9080c3bfd&phone=";

    @GetMapping   ("/getInfoByTelP")
    public String  getInfoByTelP(@RequestParam String telp){
        //将查询信息转换成实体类
        PhoneInfo phoneInfo = JSONObject.parseObject(httpclient.client(url + telp), PhoneInfo.class);
        phoneInfo.setTelp(telp);
        System.out.println(phoneInfo);
        //数据保存
        addPhoneService.save(phoneInfo);
        return httpclient.client(url + telp);
    }

    @GetMapping("/getRecord")
    public ResultMessasge getRecord(@RequestParam Integer pageNum,
                                    @RequestParam Integer pageSize){
        return ResultMessasge.success(addPhoneService.page(new Page<>(pageNum,pageSize),null));
    }

}
